package com.hh.test.crawler.gwy;

import com.hh.test.util.FileUtil;
import com.hh.test.util.HttpUtil;

public class PageCrawler {

	public static void main(String[] args) {
		String html = "";
		html += getHtmlHead();
		String dir = "G:\\公务员";
		String name = "公务员岗位列表.html";
		for (int i = 1; i < 310; i++) {
			String url = "https://www.fjkl.gov.cn/z/api.aspx?action=PositionSearch&page=%s&unitCode=&unitName=&unitType=&unitArea=&unitLevel=&positionCode=&positionName=&departmentId=&examType=&eduStatus=&hJLocation=&sex=&jobYear=&nation=&degree=&eduType=&specialPosition=&specialXQPosition=&specialty=&number=&age=&jsoncallback=jQuery191029859344300576107_1521173686211&_=1521173686215";
			String htmli = HttpUtil.getResByUrl(url.format(url, i + ""),
					"UTF-8");
			System.out.println("抽取到第几页:" + i);
			System.out
					.println(htmli = htmli
							.replace(
									"jQuery191029859344300576107_1521173686211({\"Total\":3098,\"Rows\":[\"",
									"").replace("\"]})", ""));

			html += htmli;
		}
		html += getHtmlEnd();

		FileUtil.strToFile(dir + "/" + name, "GBK", html);
	}

	static String getHtmlHead() {
		return "<!DOCTYPE html>\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\"><head> </head><body>       ";
	}

	static String getHtmlEnd() {
		return "</body></html>";
	}
}
